<?php
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class igbaseController extends JController
{
	function __construct($config = array())
	{
		parent::__construct($config);
	}
	
	function save()
	{
		$post	= JRequest::get('post');
		$model = $this->getModel();
		
		if(!$model->save($post)) 
		{
			JError::raise(2, 500, $model->getError() );
			$msg = '';
		}
		else
		{
			$msg = JText::_( 'SUCCESSFULLY SAVED' );
		}
		
		switch($this->_task)
		{
			case 'apply':
			$url = $this->applyRedirect;
			break;
			
			case 'save':
			$url = $this->redirect;
		}
		
		$this->setRedirect($url, $msg);
	}
	
	function remove()
	{
		$model = $this->getModel();
		if(!$model->remove()) 
		{
			JError::raise(2, 500, $model->getError() );
			$msg = '';
		}
		else
		{
			$msg = JText::_( 'SUCCESSFULLY DELETED' );
		}
		
		$this->setRedirect( $this->redirect, $msg);
	}
	
	function cancel()
	{
		$this->setRedirect( $this->redirect );
	}
	
	function copy()
	{
		$post	= JRequest::get('post');
		$model = $this->getModel();
		
		if ($model->copy($post)) 
		{
			$msg = JText::_('SUCCESSFULLY COPIED');
		}
		
		$this->setRedirect($this->redirect, $msg);
	}
	
	function publish()
	{
		$model = $this->getModel();
		if(!$model->publish(1)) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
		
		$this->setRedirect( $this->redirect );
	}
	
	
	function unpublish()
	{
		$model = $this->getModel();
		if(!$model->publish(0)) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
		
		$this->setRedirect( $this->redirect );
	}
	
	function moderate()
	{
		$model = $this->getModel();
		if(!$model->moderate(1)) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
		
		$this->setRedirect( $this->redirect );
	}
	
	
	function unmoderate()
	{
		$model = $this->getModel();
		if(!$model->moderate(0)) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
		
		$this->setRedirect( $this->redirect );
	}
	
	function orderup()
	{
		$model = $this->getModel();
		if(!$model->move(-1)) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
		
		$this->setRedirect( $this->redirect );
	}
	
	function orderdown()
	{
		$model = $this->getModel();
		if(!$model->move(1)) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
	
		$this->setRedirect( $this->redirect );
	}
	
	function saveorder()
	{
		$model = $this->getModel();
		
		if(!$model->saveorder()) 
		{
			JError::raiseError(2, 500, $model->getError() );
		}
		
		$msg = JText::_( 'New ordering saved' );
		$this->setRedirect( $this->redirect , $msg );
	}
}